Comparison of different methods for analysis of simple undamped pendulum with Calcpad

Input parameters

Gravitational acceleration (m/s²) - g = 9.81 ms2

Pendulum length - l = 1 m

Pendulum mass - m = 1 kg

Initial angle - θ0 = -60 ° = -1.05 rad

Maximum simulation time - tmax = 10 s

Analytical solution for small rotations

θ ≪ 1 or sin(θ) ≈ θ

-60°1mg

Differential equation - θ″ + gl·θ = 0

Angular frequency - ω =   gl·rad = 3.13 rad/s

Cyclic frequency - f = ωπ·rad = 0.498 Hz

Period - T = 1f = 2.01 s

Equation of motion - θ (t)  = θ0·cos (ω·t) 

Analytical solution for large rotations (exact)

Differential equation - θ″ + gl·sin (θ)  = 0

Incomplete elliptic integral of the first kind

F (φ; k)  = φ1   1 − k2·sin (θ) 2 dθ

Jacobi elliptic functions

Modulus - k = sin(θ02) = -0.5

am (u; k)  = $Root{F (φ; k)  = u; φ ∈ [0; 10·π]}

sn (u; k)  = sin (am (u; k) )  , cn (u; k)  = cos (am (u; k) ) 

dn (u; k)  =    1 − k·sn (u; k) 2 , cd (u; k)  = cn (u; k) dn (u; k) 

Period - Te = 4·  lg·F(π2; k) = 2.15 s

Error - δT = |TTe|Te = 6.82 %

Cyclic frequency - fe = 1Te = 0.464 Hz

Angular frequency - ωe = 2·π·rad·fe = 2.92 rad/s

Equation of motion - θe (t)  = 2·asin(k·cd(  gl·t; k))

Energy - E0 = m·l·g· (1 − cos (θ0) )  = 4.9 J

Relative error δT [%] of small displacements period versus initial angle θ0 [°] plot

0 2 4 6 8 10 12 14 0 10 20 30 40 50 60 70 80 90 x y [0.01; 0] [90; 15.28]

Solution by forward Euler method (explicit)

For that purpose, the II order equation is reduced the following system of I order equations

θ′ = ω and ω′ = gl·sin (-θ) 

The solution is performed iteratively

Step size - h = 0.05 s

Number of steps - n = tmaxh = 200

For each time step n = 200 the values for the next step will be obtained by using the following equstions

θn+1 = θn + h·ωn
ωn+1 = ωn + h·gl · sinθn

Allocate vectors

θfwE = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]
ωfwE = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]
EfwE = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]

Set initial conditions

θfwE.1 = θ01 rad = -1.05 , ωfwE.1 = 0s

Perform Euler steps

Rotation - θfwE.2 = θfwE.1 + h·ωfwE.1 = -1.05

Angular velicity - ωfwE.2 = ωfwE.1 + h·gl·sin (-θfwE.1)  = 0.425 s-1

Energy - EfwE.1 = m·l2·(12·ωfwE.12 + gl· (1 − cos (θfwE.1) ) ) = 4.9 J

Solution by backward Euler method (implicit)

The following iterative procedure is applied:

θn+1 = θn + h·ωn+1
ωn+1 = ωn + h·gl · sinθn+1

Allocate vectors

θbwE = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]
ωbwE = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]
EbwE = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]

Set initial conditions

θbwE.1 = θ01 rad = -1.05 , ωbwE.1 = 0s

Perform Euler steps

f (θ)  = θbwE.i + h·(ωbwE.i + h·gl·sin (-θ) )θ

Rotation - θbwE.2 = $Root{f (θ)  = 0; θ ∈ [-2·π; 2·π]} = -1.03

Angular velicity - ωbwE.2 = ωbwE.1 + h·gl·sin (-θbwE.2)  = 0.419 s-1

Energy - EbwE.1 = m·l2·(12·ωbwE.12 + gl· (1 − cos (θbwE.1) ) ) = 4.9 J

Solution by Crank–Nicolson method (IMEX)

The following iterative procedure is applied:

θn+1 = θn + h2 ( ωn + ωn+1 )
ωn+1 = ωn + h·gl ( sinθn + sinθn+1 )

Allocate vectors

θCN = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]
ωCN = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]
ECN = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]

Set initial conditions

θCN.1 = θ01 rad = -1.05 , ωCN.1 = 0s

Perform Euler steps

f (θ)  = θCN.i + h2·(ωCN.i + h·gl· (sin (-θCN.i)  + sin (-θ) ) )θ

Rotation - θCN.2 = $Root{f (θ)  = 0; θ ∈ [-2·π; 2·π]} = -1.04

Angular velicity - ωCN.2 = ωCN.1 + h·gl· (sin (-θCN.1)  + sin (-θCN.2) )  = 0.423 s-1

Energy - ECN.1 = m·l2·(12·ωCN.12 + gl· (1 − cos (θCN.1) ) ) = 4.9 J

Solution by Runge-Kutta RK4 method (explicit)

The following iterative procedure is applied:

First step (k₁) - k1,θ = ωi , k1,ω = gl·sin (-θi) 
Second step (k₂) - k2,θ = ωi + 0.5·h·k1,ω , k2,ω = gl·sin (- (θi + 0.5·h·k1,θ) ) 
Third step (k₃) - k3,θ = ωi + 0.5·h·k2,ω , k3,ω = gl·sin (- (θi + 0.5·h·k2,θ) ) 
Fourth step (k₄) - k4,θ = ωi + h·k3,ω , k4,ω = gl·sin (- (θi + h·k3,θ) ) 

Update values using weighted averages

θn+1 = θi + h6· (k1,θ + 2·k2,θ + 2·k3,θ + k4,θ) 
ωn+1 = ωi + h6· (k1,ω + 2·k2,ω + 2·k3,ω + k4,ω) 

Allocate vectors

θRK4 = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]
ωRK4 = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]
ERK4 = vector (n)  = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0]

Set initial conditions

θRK4.1 = θ01 rad = -1.05 , ωRK4.1 = 0s

Perform Runge-Kutta 4 steps

RK4 factors

k1,θ = ωRK4.1 = 0 s-1 , k1,ω = gl·sin (-θRK4.1)  = 8.49 s-2

k2,θ = ωRK4.1 + 0.5·h·k1,ω = 0.212 s-1

k2,ω = gl·sin (- (θRK4.1 + 0.5·h·k1,θ) )  = 8.49 s-2

k3,θ = ωRK4.1 + 0.5·h·k2,ω = 0.212 s-1

k3,ω = gl·sin (- (θRK4.1 + 0.5·h·k2,θ) )  = 8.47 s-2

k4,θ = ωRK4.1 + h·k3,ω = 0.423 s-1

k4,ω = gl·sin (- (θRK4.1 + h·k3,θ) )  = 8.44 s-2

Update values using weighted averages

Rotation - θRK4.2 = θRK4.1 + h6· (k1,θ + 2·k2,θ + 2·k3,θ + k4,θ)  = -1.04

Angular velicity - ωRK4.2 = ωRK4.1 + h6· (k1,ω + 2·k2,ω + 2·k3,ω + k4,ω)  = 0.424 s-1

Energy - ERK4.1 = m·l2·(12·ωRK4.12 + gl· (1 − cos (θRK4.1) ) ) = 4.9 J

Plot results

Rotation θ [deg] versus time t [s] plot

-100 -50 0 50 100 0 1 2 3 4 5 6 7 8 9 10 x y [0; -127.98] [9.95; 126.34]



━━━━ Small rotations
━━━━ Large rotations
· · · · · Forward Euler
━ ━ ━ Backward Euler
━ · ━  Crank–Nicolson

Energy E [J] versus time t [s] plot

0 5 10 15 20 25 30 0 1 2 3 4 5 6 7 8 9 10 x y [0; 0] [9.95; 29.85]

Comparision of Crank–Nicolson and Runge-Kutta 4 methods

Rotation θ [deg] versus time t [s] plot

-60 -40 -20 0 20 40 60 0 1 2 3 4 5 6 7 8 9 10 x y [0; -60] [9.95; 60]


━━━━ Theoretical (large rot.)
━ ━ ━ Crank–Nicolson (IMEX)
· · · · · Runge-Kutta 4 (explicit)

Absolute error Δθ [°] versus time t [s] plot

-15 -10 -5 0 5 10 15 0 1 2 3 4 5 6 7 8 9 10 x y [0; -16.17] [9.95; 15.23]


━━━━ Crank–Nicolson (IMEX)
━ ━ ━ Runge-Kutta 4 (explicit)

Energy E [J] versus time t [s] plot

4.9 4.9 4.9 4.9 4.9 0 1 2 3 4 5 6 7 8 9 10 y [0; 4.9] [9.95; 4.9]


━━━━ Theoretical (large rot.)
━ ━ ━ Crank–Nicolson (IMEX)
· · · · · Runge-Kutta 4 (explicit)